<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="Singleton.Application"%>
<%@ page import="Singleton.Local"%>
<%@ page import="utils.Functions"%>
<%@ page import="java.util.Calendar"%>
<%@ page import="java.util.GregorianCalendar"%>
<%@ page import="java.text.SimpleDateFormat"%>

<%
	SimpleDateFormat dateFormat = new SimpleDateFormat(Local.get("shortDateFormat")); 
	GregorianCalendar[] month = new GregorianCalendar[31];
	
	month[0] = new GregorianCalendar();
	if (!Functions.isNullOrEmpty(request.getParameter("date"))) {
		month[0].setTime(dateFormat.parse(request.getParameter("date")));
	} else {
		month[0].setTime(new java.util.Date());
	}
	month[0].set(Calendar.DAY_OF_MONTH,1);
	
	int lastDayOfTheMonth = 0;
	GregorianCalendar tmp = new GregorianCalendar();
	tmp.setTime(month[0].getTime());
	tmp.add(Calendar.MONTH,1);
	tmp.add(Calendar.DAY_OF_YEAR,-1);
	lastDayOfTheMonth = tmp.get(Calendar.DAY_OF_MONTH);
	
	for (int i=1;i<lastDayOfTheMonth;i++) {
		month[i]=Functions.addDays(month[0],i);
	}
	
	GregorianCalendar nextDate = new GregorianCalendar();
	nextDate.setTime(month[0].getTime());
	nextDate.add(Calendar.MONTH,1);
	GregorianCalendar prevDate = new GregorianCalendar();
	prevDate.setTime(month[0].getTime());
	prevDate.add(Calendar.MONTH,-1);
	String nextLinkDate = dateFormat.format((java.util.Date)((GregorianCalendar)nextDate).getTime());
	String prevLinkDate = dateFormat.format((java.util.Date)((GregorianCalendar)prevDate).getTime());
	
	%>
<table width="100%" cellpadding="0" cellspacing="0" border="0" id="applicationcontainer">
<tr>
    <td id="leftNav" valign="top" width="190">
    
                <div class="modulecontainer sidebar">
            <div class="first">
                <span class="first"></span>
                <span class="last"></span>
            </div>
            <div style="text-align:center;">

                <!-- Mini calendrier -->
                        <div style="border-top:1px dotted #ccc;padding-top:5px;margin-top:5px;"><%= Singleton.Local.get("today_announcement") %>&nbsp;:<br> <a href=""><%= Singleton.Local.get("day_"+today.get(Calendar.DAY_OF_WEEK)) + " " + dateFormat.format(today.getTime()) %></a></div>
						</div>
            <div class="last">
                <span class="first"></span>
                <span class="last"></span>
            </div>
        </div>
        
    
                <form method="post" action="">
        <input type=hidden name=".crumb" value="9yuiq1Z6LMk">
        <input type="hidden" name="in_titles" value="1" />
        <div class="modulecontainer sidebar quicksearch">
            <div class="first">
                <span class="first"></span>
                <span class="last"></span>
            </div>
            <div>
                <div class="hdr">
                    <strong><%= Singleton.Local.get("search_event") %></strong>
                </div>
                <div class="bdy">
                <input type="text" name="search_words" size="15"/>
                <button type="submit" name="SubmitSearch" value="Go">OK</button>
                </div>
                
            </div>
            <div class="last">
                <span class="first"></span>
                <span class="last"></span>
            </div>
        </div>
        </form>

    </td>
 


    <td valign="top" width="100%">
    <table cellpadding="0" cellspacing="0" width="100%" border="0">
    <tr>
    <td valign="top" colspan="3">
                    <div id="tabbackground">
                <div id="ymacalnav">
                    <span id="menu_day" class="bge"><a href="javascript:loadFragmentInToElement('main.jsp?view=day','calendar')"><%= Singleton.Local.get("title_day") %></a></span>
                    <span id="menu_week" class="bge"><a href="javascript:loadFragmentInToElement('main.jsp?view=week','calendar')"><%= Singleton.Local.get("title_week") %></a></span>
                    <span id="menu_month" class="bgf"><a href="javascript:loadFragmentInToElement('main.jsp?view=month','calendar')"><%= Singleton.Local.get("title_month") %></a></span>
                    <span id="menu_list" class="bge"><a href="javascript:loadFragmentInToElement('main.jsp?view=event','calendar')"><%= Singleton.Local.get("title_events") %></a></span>
                </div>
            </div>



    </td>
    </tr>
    <tr><td valign="top">
<div id="monthdataview">

<div id="calhdr"><span> <a href="javascript:loadFragmentInToElement('main.jsp?view=month&date=<%= prevLinkDate %>','calendar')"><img
	src="<%= libPath %>/images/leftl1.gif" width="16" height="16"
	border="0"></a> <a href="javascript:loadFragmentInToElement('main.jsp?view=month&date=<%= nextLinkDate %>','calendar')"><img
	src="<%= libPath %>/images/rightl1.gif" width="16" height="16"
	border="0"></a> <%= Singleton.Local.get("month_"+((int)month[0].get(Calendar.MONTH)+1)) + " " + month[0].get(Calendar.YEAR) %> </span></div>
<table class="tbldata tblcalendar" cellspacing="0" width="100%">

	<colgroup>

		<col width="14%">
		<col width="14%">
		<col width="14%">
		<col width="14%">
		<col width="14%">
		<col width="14%">
	</colgroup>

	<thead>
		<tr>

			<th><%=Singleton.Local.get("day_1")%></th>
			<th><%=Singleton.Local.get("day_2")%></th>
			<th><%=Singleton.Local.get("day_3")%></th>

			<th><%=Singleton.Local.get("day_4")%></th>
			<th><%=Singleton.Local.get("day_5")%></th>
			<th><%=Singleton.Local.get("day_6")%></th>
			<th><%=Singleton.Local.get("day_7")%></th>
		</tr>
	</thead>
	<tbody>

	<%
	int i=1;
	int jour=1;
	int j=0;
	boolean begun = false;
	while (jour<=lastDayOfTheMonth) {
		i++;
		j++;
		if (j==1) { out.println("<tr>"); }
		out.println("<td>");
		
		if (jour==1) { if (month[jour-1].get(Calendar.DAY_OF_WEEK)-1==j || j==7) { begun = true; } }
		if (!begun) { out.println("&nbsp;"); }
		else {
			%>
			<div class="calmonthhdr">
			<span class="last">[<a href=""><%= Singleton.Local.get("add") %></a>]</span>
			<a class="d" href="javascript:loadFragmentInToElement('main.jsp?view=day&date=<%= dateFormat.format(month[jour-1].getTime()) %>','calendar')">
			<%
			out.println(jour);
			%>
			</a>
			<%= calendar.Display.monthEvent(month[jour-1]) %>
			</div>
			<%
			jour++;
		}
		out.println("</td>");
		if (j==7) { out.println("</tr>"); j=0; }
	}
	if (j>0) {
		while (j<7) {
			j++;
			out.println("<td>&nbsp;</td>");
		}
		out.println("</tr>");
	}
	%>
		
	</tbody>
</table>
<div class="contentnav"><span class="last"> </span></div>
    </td></tr>
    </table>
    </td>
</tr>
</table>

<%@ include file="footer.jsp"%></div>